<template>
  <div class="UserCenter_box">
    <div class="UserCenter">
      <projectlist
        :title="dataList.titleList.text"
        :type="1"
        :projectlist="dataList.PopularCourse"
        :subtitle="dataList.titleList.en"
      >
        <template v-slot:userList>
          <div class="tabBox">
            <li
              v-for="(item, index) in dataList.tabList"
              :class="{ oddNumber: dataList.tabList.length % 2 == 0 }"
            >
              <img :src="item.img" alt="" />
              <p>{{ item.name }}</p>
              <button @click="goDetail(item.url, item.name)">点击查看</button>
            </li>
          </div>
          <h3 class="tjkc">推荐课程</h3>
        </template>
      </projectlist>
    </div>
  </div>
</template>

<script setup>
  import icon1 from "/src/assets/home/user-icon1.png";
  import icon2 from "/src/assets/home/user-icon2.png";
  import icon3 from "/src/assets/home/user-icon3.png";
  import icon4 from "/src/assets/home/user-icon4.png";
  import icon5 from "/src/assets/home/user-icon5.png";
  import icon6 from "/src/assets/home/user-icon6.png";
  import icon7 from "/src/assets/home/user-icon7.png";
  import icon8 from "/src/assets/home/user-icon8.png";
  import icon9 from "/src/assets/home/user-icon9.png";
  import { reactive, onBeforeMount, onMounted } from "vue";
  import projectlist from "@/components/projectList.vue";
  import { getCourse } from "@/api/home.js";
  import { useRouter } from "vue-router";
  const router = useRouter();
  const dataList = reactive({
    tabid: 0,
    PopularCourse: [],
    tabList: [],
    titleList: {},
    tList: [
      {
        name: "专业园地",
        img: icon1,
        url: "/Professional",
      },
      {
        name: "课程中心",
        img: icon2,
        url: "/Course",
      },
      {
        name: "虚拟模考",
        img: icon7,
        url: "http://kouqiangfangzhen.haimijiaoyu.com",
      },
    ],
    // https://zyk.icve.com.cn/portalproject/themes/default/assets/home/user-icon2.png
    // https://zyk.icve.com.cn/portalproject/themes/default/dxhzalctqitlv9umq3wtdg/sta_page/assets/projectList-0cd10861.js
    uList: [
      {
        name: "课程中心",
        img: icon2,
        url: "/Course",
      },
      // {
      // 	name: '微课中心',
      // 	img: icon3,
      // 	url: '/Microcourse'
      // },
      {
        name: "医考培训",
        img: icon4,
        url: "/Training",
      },
      {
        name: "虚拟模考",
        img: icon7,
        url: "/Exams",
      },
      {
        name: "素材中心",
        img: icon6,
        url: "/Material",
      },
    ],
    eList: [
      {
        name: "虚拟模考",
        img: icon7,
        url: "http://kouqiangfangzhen.haimijiaoyu.com",
      },
      // {
      // 	name: '就业交流',
      // 	img: icon8,
      // 	url: '/Space'
      // }
    ],
    sList: [
      {
        name: "技能训练",
        img: icon9,
        url: "/Skill",
      },
      {
        name: "虚拟模考",
        img: icon7,
        url: "http://kouqiangfangzhen.haimijiaoyu.com",
      },
      // {
      // 	name: '医师模考',
      // 	img: icon5,
      // 	url: '/Exams'
      // },
      // {
      // 	name: '就业交流',
      // 	img: icon8,
      // 	url: '/Space'
      // }
    ],
  });
  const goDetail = (url, text) => {
    if (text == "虚拟仿真" || text == "虚拟模考") {
      window.open(url);
      return;
    } else {
      router.push(url);
    }
  };
  onMounted(() => {
    // window.open('http://kouqiangfangzhen.haimijiaoyu.com/login');
    // 		return
  });
  onBeforeMount(() => {
    dataList.titleList = router.currentRoute.value.query;
    getPopularCourse();
    if (dataList.titleList.id == 1) {
      dataList.tabList = dataList.tList;
    } else if (dataList.titleList.id == 2) {
      dataList.tabList = dataList.uList;
    } else if (dataList.titleList.id == 3) {
      dataList.tabList = dataList.eList;
    } else if (dataList.titleList.id == 4) {
      dataList.tabList = dataList.sList;
    }
  });
  const getPopularCourse = () => {
    var data = {
      projectId: "dxhzalctqitlv9umq3wtdg",
      coursetype: 1,
      page: 1,
      hot: true,
      pagesize: 8,
    };

    getCourse(data).then((res) => {
      dataList.PopularCourse = JSON.parse(res.list).obj;
    });
  };
</script>

<style lang="scss" scoped>
  $width: 774px;

  @media screen and (min-width: 1200px) {
    .UserCenter_box {
      background-color: #fafafa;

      .UserCenter {
        width: $width;
        margin: 0 auto;
        padding-top: 26px;
      }
    }

    .tjkc {
      width: $width;
      text-align: center;
      font-size: 20px;
      font-weight: bold;
      color: #000;
      margin-top: 30px;
    }

    .tabBox {
      margin-top: 26px;
      margin-left: -11px;
      margin-right: -11px;
      display: flex;
      justify-content: space-between;

      li {
        // width: 243px;
        flex: 1;
        height: 262px;
        margin: 0 11px;
        background: #ffffff;
        display: flex;
        flex-direction: column;
        align-items: center;

        img {
          width: 108px;
          height: 108px;
          margin-top: 28px;
        }

        p {
          min-width: 88px;
          height: 29px;
          font-size: 20px;
          margin: 16px 0;
          font-family: Microsoft YaHei-Semibold, Microsoft YaHei;
          font-weight: bold;
          color: #000;
        }

        button {
          height: 25px;
          line-height: 25px;
          padding: 0 12px;
          background: #e8f6fb;
          border-radius: 12px;
          font-size: 14px;
          font-weight: bold;
          color: #1cabd9;
          border: none;
          cursor: pointer;
        }
      }
      li:hover {
        background-color: #1cabd9;
        p {
          color: #ffffff;
        }
        button {
          background-color: #ffffff;
        }
      }
    }
  }

  @media screen and (max-width: 1200px) {
    .UserCenter_box {
      background-color: #fafafa;

      .UserCenter {
        width: 95vw;
        margin: 0 auto;
        margin-top: 5vw;
      }
    }

    .tjkc {
      width: 95vw;
      text-align: center;
      font-size: 6vw;
      color: #333333;
      margin-top: 6vw;
      margin-bottom: 6vw;
    }

    .tabBox {
      margin-top: 6vw;
      width: 95vw;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;

      li {
        width: 28vw;
        background: #ffffff;
        box-shadow: 0px 0px 8px 4px rgba(0, 0, 0, 0.02);
        border-radius: 1vw;
        display: flex;
        flex-direction: column;
        align-items: center;
        margin: 0 1vw 2vw 1vw;
        padding: 2vw 0;

        img {
          width: 15vw;
          height: 15vw;
        }

        p {
          min-width: 12vw;
          font-size: 4vw;
          margin: 3vw 0;
          font-family: Microsoft YaHei-Semibold, Microsoft YaHei;
          font-weight: 600;
          color: #333333;
        }

        button {
          padding: 1vw 3vw;
          background: rgba(28, 171, 217, 0.1);
          border-radius: 5vw;
          font-size: 2.4vw;
          color: #1cabd9;
          border: none;
          cursor: pointer;
        }
      }
      .oddNumber {
        width: 45vw;
      }
    }
    .tabBox:after {
      content: "";
      width: 28vw;
    }
  }
</style>
